{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "983yjns496tx"
   },
   "source": [
    "[![Kaggle](https://kaggle.com/static/images/open-in-kaggle.svg)](https://kaggle.com/kernels/welcome?src=https://github.com/pixeltable/pixeltable/blob/master/docs/release/tutorials/working-with-together.ipynb)&nbsp;&nbsp;\n",
    "[![Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/pixeltable/pixeltable/blob/master/docs/release/tutorials/working-with-together.ipynb)\n",
    "\n",
    "# Working with Together AI in Pixeltable\n",
    "\n",
    "### Prerequisites\n",
    "- A Together AI account with an API key (https://api.together.ai/settings/api-keys)\n",
    "\n",
    "### Important Notes\n",
    "\n",
    "- Together.ai usage may incur costs based on your Together.ai plan.\n",
    "- Be mindful of sensitive data and consider security measures when integrating with external services.\n",
    "\n",
    "First you'll need to install required libraries and enter your Together API key."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "9pckrD01ik-e"
   },
   "outputs": [],
   "source": [
    "%pip install -q pixeltable together"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "id": "AQ6_Py7_7d0r",
    "outputId": "f8b55e8d-82dd-404c-aca4-14613702573e"
   },
   "outputs": [],
   "source": [
    "import os\n",
    "import getpass\n",
    "\n",
    "if 'TOGETHER_API_KEY' not in os.environ:\n",
    "    os.environ['TOGETHER_API_KEY'] = getpass.getpass('Together API Key: ')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Now let's create a Pixeltable directory to hold the tables for our demo."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "id": "brtjK-88tTSS",
    "outputId": "b7c720d8-7fa3-40fd-8246-98025c4116c2"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Connected to Pixeltable database at: postgresql://postgres:@/pixeltable?host=/Users/asiegel/.pixeltable/pgdata\n",
      "Created directory `together_demo`.\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<pixeltable.catalog.dir.Dir at 0x357da61f0>"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pixeltable as pxt\n",
    "\n",
    "pxt.drop_dir('together_demo', force=True)  # Ensure a clean slate for the demo\n",
    "pxt.create_dir('together_demo')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "bGN-wW6nvcz0"
   },
   "source": [
    "## Completions"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "97A0XhuR-YMB"
   },
   "source": [
    "Now we create a table in Pixeltable, with three columns:\n",
    "\n",
    "- a column to hold the inputs (prompts);\n",
    "- a computed column that calls the Together AI completions API and stores the JSON response;\n",
    "- another computed column that extracts the completion from the response JSON."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "id": "hgy_gXmIu7jM",
    "outputId": "7264b19f-cd96-44cf-9e49-f27741298a66"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Created table `completions`.\n",
      "Added 0 column values with 0 errors.\n",
      "Added 0 column values with 0 errors.\n"
     ]
    }
   ],
   "source": [
    "from pixeltable.functions.together import completions\n",
    "\n",
    "t = pxt.create_table('together_demo.completions', {'input': pxt.StringType()})\n",
    "\n",
    "# We'll use the lightweight Mistral-7B-Instruct model for this demo, but you can use\n",
    "# any model supported by Together AI.\n",
    "\n",
    "t['output'] = completions(prompt=t.input, model='mistralai/Mistral-7B-Instruct-v0.3', max_tokens=300)\n",
    "t['response'] = t.output.choices[0].text"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Here's the schema of the new table:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 129
    },
    "id": "QzeImqeKpkmh",
    "outputId": "0420a93b-c1e2-4ade-e798-2cc3238deb4d"
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<style type=\"text/css\">\n",
       "#T_a8766 th {\n",
       "  text-align: center;\n",
       "}\n",
       "#T_a8766_row0_col0, #T_a8766_row0_col1, #T_a8766_row0_col2, #T_a8766_row1_col0, #T_a8766_row1_col1, #T_a8766_row1_col2, #T_a8766_row2_col0, #T_a8766_row2_col1, #T_a8766_row2_col2 {\n",
       "  white-space: pre-wrap;\n",
       "  text-align: left;\n",
       "}\n",
       "</style>\n",
       "<table id=\"T_a8766\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th id=\"T_a8766_level0_col0\" class=\"col_heading level0 col0\" >Column Name</th>\n",
       "      <th id=\"T_a8766_level0_col1\" class=\"col_heading level0 col1\" >Type</th>\n",
       "      <th id=\"T_a8766_level0_col2\" class=\"col_heading level0 col2\" >Computed With</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td id=\"T_a8766_row0_col0\" class=\"data row0 col0\" >input</td>\n",
       "      <td id=\"T_a8766_row0_col1\" class=\"data row0 col1\" >string</td>\n",
       "      <td id=\"T_a8766_row0_col2\" class=\"data row0 col2\" ></td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td id=\"T_a8766_row1_col0\" class=\"data row1 col0\" >output</td>\n",
       "      <td id=\"T_a8766_row1_col1\" class=\"data row1 col1\" >json</td>\n",
       "      <td id=\"T_a8766_row1_col2\" class=\"data row1 col2\" >completions(input, max_tokens=300, model='mistralai/Mistral-7B-Instruct-v0.3')</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td id=\"T_a8766_row2_col0\" class=\"data row2 col0\" >response</td>\n",
       "      <td id=\"T_a8766_row2_col1\" class=\"data row2 col1\" >json</td>\n",
       "      <td id=\"T_a8766_row2_col2\" class=\"data row2 col2\" >output.choices[0].text</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n"
      ],
      "text/plain": [
       "table 'completions'\n",
       "\n",
       "Column Name   Type                                                                  Computed With\n",
       "      input string                                                                               \n",
       "     output   json completions(input, max_tokens=300, model='mistralai/Mistral-7B-Instruct-v0.3')\n",
       "   response   json                                                         output.choices[0].text"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "t"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Now we can insert some queries into our new table."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 152
    },
    "id": "IkMM7OYb5rQ_",
    "outputId": "a1bff564-617d-4e2b-fcc8-423763f17c11"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Computing cells: 100%|████████████████████████████████████████████| 6/6 [00:09<00:00,  1.66s/ cells]\n",
      "Inserting rows into `completions`: 2 rows [00:00, 256.77 rows/s]\n",
      "Computing cells: 100%|████████████████████████████████████████████| 6/6 [00:09<00:00,  1.66s/ cells]\n",
      "Inserted 2 rows with 0 errors.\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "UpdateStatus(num_rows=2, num_computed_values=6, num_excs=0, updated_cols=[], cols_with_excs=[])"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Start a conversation\n",
    "t.insert([\n",
    "    {'input': 'On November 19, 1863, '},\n",
    "    {'input': 'Beethoven was the first '}\n",
    "])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Querying the results:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th>input</th>\n",
       "      <th>response</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>On November 19, 1863,</td>\n",
       "      <td>150,000 Union soldiers gathered at Gettysburg, Pennsylvania, for a speech by President Abraham Lincoln. The speech, now known as the Gettysburg Address, was only 272 words long, but it has become one of the most famous speeches in American history.\n",
       "\n",
       "In the speech, Lincoln redefined the purpose of the Civil War. He said that the war was not just about preserving the Union, but also about establishing a government &quot;of the people, by the people, for the people.&quot; Lincoln also emphasized the impo ...... he full text of the Gettysburg Address:\n",
       "\n",
       "Four score and seven years ago our fathers brought forth on this continent a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal.\n",
       "\n",
       "Now we are engaged in a great civil war, testing whether that nation, or any nation so conceived and so dedicated, can long endure. We are met on a great battle-field of that war. We have come to dedicate a portion of that field, as a final resting place for those who here gave</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>Beethoven was the first</td>\n",
       "      <td>&gt; to write a symphony in C minor, and it was the first to be performed in the new Berlin Philharmonic Hall.\n",
       "\n",
       "The first symphony in C minor was Mozart&#x27;s Symphony No. 40 in C minor, K. 550, which was composed in 1788. Beethoven&#x27;s Symphony No. 3 in C minor, Op. 55, commonly known as the Eroica, was composed in 1803-1804 and was the first symphony to be performed in the new Berlin Philharmonic Hall, but it was not the first symphony in C minor.\n",
       "\n",
       "&gt; Beethoven&#x27;s Symphony No. 5 in C minor, Op. 67, is one of the most famous and recognizable pieces of classical music.\n",
       "\n",
       "Yes, that is correct. Beethoven&#x27;s Symphony No. 5 in C minor, Op. 67, is one of the most famous and recognizable pieces of classical music. It was composed in 1808 and is often considered a masterpiece of the symphonic form. The opening motif of the symphony, consisting of four notes (short-short-short-long), is one of the most famous and recognizable melodies in Western music.</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>"
      ],
      "text/plain": [
       "                      input                                           response\n",
       "0    On November 19, 1863,   150,000 Union soldiers gathered at Gettysburg,...\n",
       "1  Beethoven was the first   \\n\\n> to write a symphony in C minor, and it w..."
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "t.select(t.input, t.response).head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "BJLTeHjCvHys"
   },
   "source": [
    "## Chat Completions"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "id": "OAIwzWQcslNN",
    "outputId": "80289c1a-4972-4e3c-c36a-4bc095b6948a"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Created table `chat`.\n",
      "Added 0 column values with 0 errors.\n",
      "Added 0 column values with 0 errors.\n"
     ]
    }
   ],
   "source": [
    "from pixeltable.functions.together import chat_completions\n",
    "\n",
    "chat_t = pxt.create_table('together_demo.chat', {'input': pxt.StringType()})\n",
    "\n",
    "# The chat-completions API expects JSON-formatted input:\n",
    "messages = [{'role': 'user', 'content': chat_t.input}]\n",
    "\n",
    "# This example shows how additional parameters from the Together API can be used in\n",
    "# Pixeltable to customize the model behavior.\n",
    "chat_t['output'] = chat_completions(\n",
    "    messages=messages,\n",
    "    model='mistralai/Mixtral-8x7B-Instruct-v0.1',\n",
    "    max_tokens=300,\n",
    "    stop=['\\n'],\n",
    "    temperature=0.7,\n",
    "    top_p=0.9,\n",
    "    top_k=40,\n",
    "    repetition_penalty=1.1,\n",
    "    logprobs=1,\n",
    "    echo=True\n",
    ")\n",
    "chat_t['response'] = chat_t.output.choices[0].message.content"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 152
    },
    "id": "yM5R4ElHuR4k",
    "outputId": "e52f14e8-2015-4b28-c218-2c516db9441b"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Computing cells: 100%|████████████████████████████████████████████| 6/6 [00:01<00:00,  3.16 cells/s]\n",
      "Inserting rows into `chat`: 2 rows [00:00, 106.92 rows/s]\n",
      "Computing cells: 100%|████████████████████████████████████████████| 6/6 [00:01<00:00,  3.11 cells/s]\n",
      "Inserted 2 rows with 0 errors.\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th>input</th>\n",
       "      <th>response</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>How many species of felids have been classified?</td>\n",
       "      <td>There are 41 species of felids, or members of the family Felidae, that have been classified. This includes well-known cats like lions, tigers, and domestic cats, as well as lesser-known species such as the fishing cat and the flat-headed cat. This number can vary slightly depending on the source and the taxonomic scheme used to classify the animals.</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>Can you make me a coffee?</td>\n",
       "      <td>I&#x27;m sorry for any confusion, but I&#x27;m unable to physically make you a coffee as I&#x27;m just a text-based program running on computers around the world. However, I can certainly help you find a recipe or provide instructions on how to make one if you&#x27;d like! Would you be interested in that?</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>"
      ],
      "text/plain": [
       "                                              input  \\\n",
       "0  How many species of felids have been classified?   \n",
       "1                         Can you make me a coffee?   \n",
       "\n",
       "                                            response  \n",
       "0   There are 41 species of felids, or members of...  \n",
       "1   I'm sorry for any confusion, but I'm unable t...  "
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Start a conversation\n",
    "chat_t.insert([\n",
    "    {'input': 'How many species of felids have been classified?'},\n",
    "    {'input': 'Can you make me a coffee?'}\n",
    "])\n",
    "chat_t.select(chat_t.input, chat_t.response).head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "wfqSt-xP481L"
   },
   "source": [
    "## Embeddings"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "id": "utRyNyr2498C",
    "outputId": "d58e8189-daa2-4e8d-a9f5-c537f297988d"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Created table `embeddings`.\n",
      "Added 0 column values with 0 errors.\n"
     ]
    }
   ],
   "source": [
    "from pixeltable.functions.together import embeddings\n",
    "\n",
    "emb_t = pxt.create_table('together_demo.embeddings', {'input': pxt.StringType()})\n",
    "emb_t['embed'] = embeddings(\n",
    "    input=emb_t.input,\n",
    "    model='togethercomputer/m2-bert-80M-8k-retrieval'\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "id": "gZ3dlpcm5Ide",
    "outputId": "a340681c-309f-45e7-c9fa-f6d5aec1e69a"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Computing cells:  50%|██████████████████████                      | 1/2 [00:00<00:00,  3.27 cells/s]\n",
      "Inserting rows into `embeddings`: 1 rows [00:00, 233.71 rows/s]\n",
      "Computing cells: 100%|████████████████████████████████████████████| 2/2 [00:00<00:00,  6.30 cells/s]\n",
      "Inserted 1 row with 0 errors.\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "UpdateStatus(num_rows=1, num_computed_values=2, num_excs=0, updated_cols=[], cols_with_excs=[])"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "emb_t.insert(input='Together AI provides a variety of embeddings models.')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 280
    },
    "id": "fBGsafse5dcc",
    "outputId": "41d690df-b165-4454-8dc3-b99f9af0e837"
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th>input</th>\n",
       "      <th>embed</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>Together AI provides a variety of embeddings models.</td>\n",
       "      <td>[ 0.016 -0.21   0.201  0.153 -0.339  0.164 ... -0.049  0.003 -0.157  0.178 -0.063 -0.168]</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>"
      ],
      "text/plain": [
       "                                               input  \\\n",
       "0  Together AI provides a variety of embeddings m...   \n",
       "\n",
       "                                               embed  \n",
       "0  [0.016232457, -0.20974171, 0.20096539, 0.15308...  "
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "emb_t.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "WT5jPgfY5sPl"
   },
   "source": [
    "## Image Generations"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "id": "qE5e7zyn5vfR",
    "outputId": "171ab465-83f9-4c2e-ff2d-929f850a5275"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Created table `images`.\n",
      "Added 0 column values with 0 errors.\n"
     ]
    }
   ],
   "source": [
    "from pixeltable.functions.together import image_generations\n",
    "\n",
    "image_t = pxt.create_table('together_demo.images', {'input': pxt.StringType(), 'negative_prompt': pxt.StringType(nullable=True)})\n",
    "image_t['img'] = image_generations(image_t.input, model='stabilityai/stable-diffusion-xl-base-1.0')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "id": "9NEd5yLI57Y5",
    "outputId": "666d6e2b-a3a7-4911-bcd1-8f25c6648a1f"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Computing cells:   0%|                                                    | 0/2 [00:00<?, ? cells/s]\n",
      "Inserting rows into `images`: 1 rows [00:00, 577.65 rows/s]\n",
      "Computing cells: 100%|███████████████████████████████████████████| 2/2 [00:00<00:00, 535.50 cells/s]\n",
      "Inserted 1 row with 0 errors.\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "UpdateStatus(num_rows=1, num_computed_values=2, num_excs=0, updated_cols=[], cols_with_excs=[])"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Start generating Images\n",
    "image_t.insert([\n",
    "  {'input': 'A friendly dinosaur playing tennis in a cornfield'}\n",
    "])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 270
    },
    "id": "7gw5jciV6UKt",
    "outputId": "b3cb285a-29e1-4eb8-a395-a726823adb76"
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<style type=\"text/css\">\n",
       "#T_0d711 th {\n",
       "  text-align: center;\n",
       "}\n",
       "#T_0d711_row0_col0, #T_0d711_row0_col1, #T_0d711_row0_col2, #T_0d711_row1_col0, #T_0d711_row1_col1, #T_0d711_row1_col2, #T_0d711_row2_col0, #T_0d711_row2_col1, #T_0d711_row2_col2 {\n",
       "  white-space: pre-wrap;\n",
       "  text-align: left;\n",
       "}\n",
       "</style>\n",
       "<table id=\"T_0d711\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th id=\"T_0d711_level0_col0\" class=\"col_heading level0 col0\" >Column Name</th>\n",
       "      <th id=\"T_0d711_level0_col1\" class=\"col_heading level0 col1\" >Type</th>\n",
       "      <th id=\"T_0d711_level0_col2\" class=\"col_heading level0 col2\" >Computed With</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td id=\"T_0d711_row0_col0\" class=\"data row0 col0\" >input</td>\n",
       "      <td id=\"T_0d711_row0_col1\" class=\"data row0 col1\" >string</td>\n",
       "      <td id=\"T_0d711_row0_col2\" class=\"data row0 col2\" ></td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td id=\"T_0d711_row1_col0\" class=\"data row1 col0\" >negative_prompt</td>\n",
       "      <td id=\"T_0d711_row1_col1\" class=\"data row1 col1\" >string</td>\n",
       "      <td id=\"T_0d711_row1_col2\" class=\"data row1 col2\" ></td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td id=\"T_0d711_row2_col0\" class=\"data row2 col0\" >img</td>\n",
       "      <td id=\"T_0d711_row2_col1\" class=\"data row2 col1\" >image</td>\n",
       "      <td id=\"T_0d711_row2_col2\" class=\"data row2 col2\" >image_generations(input, model='stabilityai/stable-diffusion-xl-base-1.0')</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n"
      ],
      "text/plain": [
       "table 'images'\n",
       "\n",
       "    Column Name   Type                                                              Computed With\n",
       "          input string                                                                           \n",
       "negative_prompt string                                                                           \n",
       "            img  image image_generations(input, model='stabilityai/stable-diffusion-xl-base-1.0')"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "image_t"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 805
    },
    "id": "uHeIS3am88X6",
    "outputId": "c771cc70-fb02-45db-8543-720fa411547d"
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th>input</th>\n",
       "      <th>negative_prompt</th>\n",
       "      <th>img</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>A friendly dinosaur playing tennis in a cornfield</td>\n",
       "      <td>None</td>\n",
       "      <td><div class=\"pxt_image\" style=\"width:480px;\">\n",
       "                <img src=\"\" width=\"480\" />\n",
       "            </div></td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>"
      ],
      "text/plain": [
       "                                               input negative_prompt  \\\n",
       "0  A friendly dinosaur playing tennis in a cornfield            None   \n",
       "\n",
       "                                                 img  \n",
       "0  <PIL.JpegImagePlugin.JpegImageFile image mode=...  "
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "image_t.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "lTtQcjKQAlis"
   },
   "source": [
    "### Learn More\n",
    "\n",
    "To learn more about advanced techniques like RAG operations in Pixeltable, check out the [RAG Operations in Pixeltable](https://pixeltable.readme.io/docs/rag-operations-in-pixeltable) tutorial.\n",
    "\n",
    "You can also look at how to work with images in Pixeltable: [Working with Images](https://pixeltable.readme.io/docs/working-with-images).\n",
    "\n",
    "If you have any questions, don't hesitate to reach out."
   ]
  }
 ],
 "metadata": {
  "colab": {
   "provenance": []
  },
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.19"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
